<?php
/**
 * Created by PhpStorm.
 * User: tangmusen
 * Date: 2017/10/30
 * Time: 11:08
 */
namespace app\home\controller;

use think\Controller;
use think\Db;
use think\Request;

class Notice extends Base
{
    /**
     * 公告
     */
    public function index(){

        $limit = 20;
        $sys_data = Db::name('notice')
            ->order('id desc')
            ->limit($limit)
            ->select();
        foreach ($sys_data as $k=>$v){
            $sys_data[$k]['content']     = mb_substr($v['info'],0,15,'utf-8').'...';
            $sys_data[$k]['create_time'] = date('m-d H:i',strtotime($v['create_time']));
        }
        $uid   = session('uid');
        $my_data = Db::name('member_msg')
            ->where(array('uid'=>$uid))
            ->order('id desc')
            ->limit($limit)
            ->select();
        foreach ($my_data as $k=>$v){
            $my_data[$k]['content']     = mb_substr($v['content'],0,15,'utf-8').'...';
            $my_data[$k]['create_time'] = date('m-d H:i',strtotime($v['create_time']));
        }
        return view('',[
            'sys_data'=>$sys_data,
            'my_data' =>$my_data
        ]);
    }

    /**
     * 具体消息
     */
    public function detail(Request $request){
        $id   = $request->param('id');
        $type = $request->param('type');
        if($type==1){
            $content = Db::name('notice')->where('id',$id)->find();
        }
        if($type==2){
            $content = Db::name('member_msg')->field('id,content as info,create_time,uid')->where('id',$id)->find();
            $content['content'] = "";
        }
        return view('',[
            'data' =>$content
        ]);


    }

    /**
     * 具体消息
     */
    public function detail_app(Request $request){
        $id   = $request->param('id');
        $type = $request->param('type')?$request->param('type'):1;
        if($type==1){
            $content = Db::name('notice')->where('id',$id)->find();
        }
        if($type==2){
            $content = Db::name('member_msg')->field('id,content as info,create_time,uid')->where('id',$id)->find();
            $content['content'] = "";
        }
        return view('',[
            'data' =>$content
        ]);


    }


}